package com.woniuxy.carType.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniuxy.carType.common.RedisConst;
import com.woniuxy.carType.model.entity.Car;
import com.woniuxy.carType.service.CarService;
import com.woniuxy.carType.mapper.CarMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.awt.print.Book;

/**
* @author liboyang
* @description 针对表【car】的数据库操作Service实现
* @createDate 2024-10-19 11:04:29
*/
@Service
public class CarServiceImpl extends ServiceImpl<CarMapper, Car>
    implements CarService{
    @Autowired
    private CarMapper carMapper;

    @Override
    @Cacheable(cacheNames = RedisConst.CAR_LIST, keyGenerator = "keyGenerator")
    public Page<Car> list(int pageNum, int pageSize) {
        Page<Car> bookPage = new Page<>(pageNum, pageSize);

        Page<Car> page = carMapper.selectPage(bookPage, null);

        return page;
    }

    @Override
    public Page<Car> findByType(int pageNum, int pageSize, int typeId) {
        Page<Car> page = new Page<>(pageNum, pageSize);
        LambdaQueryWrapper<Car> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Car::getCarTypeId, typeId);
        wrapper.orderByDesc(Car::getDateRegistration);
        carMapper.selectPage(page, wrapper);
        return page;
    }
}




